package com.vortex.cloud.zhsw.xinyang.domain;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.*;

import javax.persistence.GeneratedValue;
import javax.persistence.MappedSuperclass;
import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * @author : lc
 * @description : Founded by LC
 * @create :2022-03-17 15:02:16
 */
@MappedSuperclass
public abstract class AbstractBaseModel implements Serializable {

    @TableId(value = "id", type = IdType.ASSIGN_ID)
    @GeneratedValue(generator = "JDBC")
    private String id;

    @TableField(value = "create_time", fill = FieldFill.INSERT, insertStrategy = FieldStrategy.NOT_EMPTY)
    private LocalDateTime createTime;

    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;

    @TableField(value = "tenant_id", insertStrategy = FieldStrategy.NOT_EMPTY)
    private String tenantId;

    @TableField(value = "division_id", insertStrategy = FieldStrategy.NOT_EMPTY)
    private String divisionId;

    @TableField(value = "is_deleted", fill = FieldFill.INSERT)
    @TableLogic
    private Boolean deleted;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }

    public String getDivisionId() {
        return divisionId;
    }

    public void setDivisionId(String divisionId) {
        this.divisionId = divisionId;
    }

    public Boolean getDeleted() {
        return deleted;
    }

    public void setDeleted(Boolean deleted) {
        this.deleted = deleted;
    }

    @Override
    public String toString() {
        return JSONUtil.toJsonStr(this);
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    public void initSave() {
        this.createTime = LocalDateTime.now();
    }

    public void initUpdate() {
        this.updateTime = LocalDateTime.now();
    }

    public void initDate() {
        initSave();
        this.updateTime = this.createTime;
    }
}
